package com.smbms.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.smbms.pojo.Provider;
import com.smbms.service.provider.ProviderService;

@Controller
public class ProviderController {

	@Autowired
	ProviderService providerService;
		
	@RequestMapping("/provider.html")
		public String providerList(HttpServletRequest request,
				String queryProCode, String queryProName,@RequestParam(defaultValue="1")Integer pageIndex) {
			List<Provider> pList=providerService.getProviderList();
			request.setAttribute("providerList",pList);
			PageHelper.startPage(pageIndex, 8);
			List<Provider> providerList=providerService.getProviderListCN(queryProCode, queryProName);
				request.setAttribute("providerList",providerList);
				
				PageInfo<Provider> pInfo=new PageInfo<Provider>(providerList);
				request.setAttribute("totalCount", pInfo.getTotal());
				request.setAttribute("currentPageNo", pInfo.getPageNum());
				request.setAttribute("totalPageCount", pInfo.getPages());
		return "providerlist";
		}
}
